<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //模拟获取 用户数据、用户的订单数据、订单的商品数据
        function getUser() {
            setTimeout(()=> {
                let data = '张三'
                //将数据传入next
                it.next(data)
            },1000)
        }
        function getOrder() {
            setTimeout(()=> {
                let data = '订单A'
                it.next(data)
            },1000)
        }
        function getGoogs() {
            setTimeout(()=> {
                let data = '商品B'
                it.next(data)
            },1000)
        }

        function * gen() {
            let user = yield getUser()
            //拿到用户
            console.log(user)
            let order = yield getOrder()
            //拿到订单
            console.log(order)
            let goods =  yield getGoogs()
            //拿到商品
            console.log(goods)
        }
        let it = gen()
        it.next()
    </script>
</body>
</html>